const Router = require('koa-router')
const { verifyToken } = require('@/utils/jwt')
const questionValidate = require('@/middlewares/validateMiddlewares/questionValidate')
const {
  validateSlideCode
} = require('@/middlewares/validateMiddlewares/userValidate')
const questionController = require('@/controller/questionController')
const { verifyAdmin } = require('@/middlewares/validateMiddlewares/verifyAdmin')
const {
  verifyHasActive
} = require('@/middlewares/validateMiddlewares/verifyHasActive')

const router = new Router()

/**
 * 获取问题列表
 */
router.get(
  '/list',
  verifyToken(),
  // 需要用户已经激活了code
  verifyHasActive(),
  questionValidate.listQuestionValidate,
  questionController.listQuestion
)

/**
 * 创建问题列表
 */
router.post(
  '/create',
  verifyToken(),
  verifyAdmin(),
  questionValidate.createQuestionValidate,
  questionController.createQuestion
)

/**
 * 删除问题列表
 */
router.delete(
  '/delete',
  validateSlideCode(),
  verifyToken(),
  verifyAdmin(),
  questionValidate.delQuestionsValidate,
  questionController.delQuestions
)

/**
 * 问题排序
 */
router.put(
  '/sort',
  verifyToken(),
  verifyAdmin(),
  questionValidate.delQuestionsValidate,
  questionController.sortQuestions
)

module.exports = router
